local M = require "packages/mamashengde/record/Made"

local moli = fk.CreateSkill {
  name = "wuguotai__moli",
  tags = { M.HenshinSkill },
}

Fk:loadTranslationTable {
  ["wuguotai__moli"] = "魔力",
  [":wuguotai__moli"] = "<a href='#made_henshin_skill'><font color='pink'>变身技</font></a>（0/5），游戏开始时或当你场上的牌发生变化时，你获得1点魔力；"..
  "当你失去牌时，你<a href='wuguotai__Henshin'><font color='pink'>进行吟唱并变身</font></a>。",
  ["wuguotai__Henshin"] = "在对应的时机点，若你的魔力已达上限，你可以吟唱咒语并变身为闪耀战姬！<br>" ..
  "<b>凤守</b>：当你变身后，你可以重新分配与你距离为1的角色的座次，然后消耗任意魔力，令等量名角色受到的火焰伤害+1。<br>" ..
  "<b>苏生</b>：当称号与你相同的角色进入濒死状态时，你可以消耗任意魔力令其回复等量的体力（若其不为你则额外回复等量魔力），然后你摸等量张牌。",

  ["$wuguotai__moli1"] = "降临吧——属于我的真实姿态！", -- 吟唱
  ["$wuguotai__moli2"] = "降临吧——属于我的真实姿态！",
}

moli:addEffect(fk.GameStart, {
  mute = true,
  can_trigger = function(self, event, target, player, data)
    return  player:hasSkill(moli.name) and M.getMaryoku(player) < M.getMaryokuMax(player)
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    M.changeMaryoku(player, 1, moli.name)
  end,
})

moli:addEffect(fk.AfterCardsMove, {
  mute = true,
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(moli.name) and M.getMaryoku(player) < M.getMaryokuMax(player) then
      for _, move in ipairs(data) do
        if (move.to and move.to == player and (move.toArea == Card.PlayerJudge or move.toArea == Card.PlayerEquip))
        or (move.from and move.from == player and (move.fromArea == Card.PlayerJudge or move.fromArea == Card.PlayerEquip)) then
          return true
        end
      end
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    M.changeMaryoku(player, 1, moli.name)
  end,
})

moli:addEffect(fk.AfterCardsMove, {
  anim_type = "big",
  can_trigger = function (self, event, target, player, data)
    if player:hasSkill(moli.name) and M.getMaryoku(player) >= M.getMaryokuMax(player) and player.general == "shine__wuguotai" then
      for _, move in ipairs(data) do
        if move.from == player then
          for _, info in ipairs(move.moveInfo) do
            if info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip then
              return true
            end
          end
        end
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local target_general = "shine2__wuguotai" -- 目标武将
    if M.enterHenshin(player, target_general, moli.name) then
        -- 变身成功后的处理
        room:notifySkillInvoked(player, moli.name, "positive")
    end
  end,
})

moli:addAcquireEffect(function (self, player)
  if M.getMaryokuMax(player) == 0 then
    M.setMaryokuMax(player, 5, moli.name)
  end
end)

return moli